{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.1安装Requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages\r\n"
     ]
    }
   ],
   "source": [
    "! pip install requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.2获取响应内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:24:14.771443Z",
     "start_time": "2019-01-04T12:24:13.335567Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "文本编码: UTF-8\n",
      "响应状态码: 200\n",
      "字符串方式的响应体: \n",
      "<!DOCTYPE html>\n",
      "<html lang=\"zh-CN\">\n",
      "<head>\n",
      "<meta charset=\"UTF-8\">\n",
      "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n",
      "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\n",
      "<title>唐松 Santos</title>\n",
      "<meta name=\"description\" content=\"这是唐松 Santos的个人博客，《Python 网络爬虫: 从入门到实践》作者\" />\n",
      "<meta name=\"keywords\" content=\"唐松 Santos, Python, 网络爬虫, Python 网络爬虫: 从入门到实践, Python 爬虫, 大数据\" />\n",
      "<link rel=\"apple-touch-icon\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/images/icon_32.png\">\n",
      "<link rel=\"apple-touch-icon\" sizes=\"152x152\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/images/icon_152.png\">\n",
      "<link rel=\"apple-touch-icon\" sizes=\"167x167\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/images/icon_167.png\">\n",
      "<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/images/icon_180.png\">\n",
      "<link rel=\"icon\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/images/icon_32.png\" type=\"image/x-icon\">\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/css/bootstrap.min.css\">\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/css/font-awesome.min.css\">\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/js/jquery.min.js\"></script>\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/js/bootstrap.min.js\"></script>\n",
      "<link rel=\"stylesheet\" href=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/style.css\">\n",
      "<link rel=\"pingback\" href=\"http://www.santostang.com/xmlrpc.php\" />\n",
      "<link rel=\"icon\" href=\"http://www.santostang.com/wp-content/uploads/2018/07/cropped-IMG_0423-min-32x32.jpg\" sizes=\"32x32\" />\n",
      "<link rel=\"icon\" href=\"http://www.santostang.com/wp-content/uploads/2018/07/cropped-IMG_0423-min-192x192.jpg\" sizes=\"192x192\" />\n",
      "<link rel=\"apple-touch-icon-precomposed\" href=\"http://www.santostang.com/wp-content/uploads/2018/07/cropped-IMG_0423-min-180x180.jpg\" />\n",
      "<meta name=\"msapplication-TileImage\" content=\"http://www.santostang.com/wp-content/uploads/2018/07/cropped-IMG_0423-min-270x270.jpg\" />\n",
      "<style type=\"text/css\">\n",
      "a{color:#1e73be}\n",
      "a:hover{color:#2980b9!important}\n",
      "#header{background-color:#1e73be}\n",
      ".widget .widget-title::after{background-color:#1e73be}\n",
      ".uptop{border-left-color:#1e73be}\n",
      "#titleBar .toggle:before{background:#1e73be}\n",
      "</style>\n",
      "</head>\n",
      "\n",
      "<body>\n",
      "<header id=\"header\">\n",
      "    <div class=\"avatar\"><a href=\"http://www.santostang.com\" title=\"唐松Santos\"><img src=\"http://www.santostang.com/wp-content/uploads/2018/07/IMG_0423-min.jpg\" alt=\"唐松Santos\" class=\"img-circle\" width=\"50%\"></a></div>\n",
      "    <h1 id=\"name\">唐松Santos</h1>\n",
      "    <div class=\"sns\">\n",
      "                <a href=\"https://www.zhihu.com/people/santostang\" target=\"_blank\" rel=\"nofollow\" title=\"Weibo\"><i class=\"fa fa-weibo\" aria-hidden=\"true\"></i></a>        <a href=\"https://www.linkedin.com/in/santostang\" target=\"_blank\" rel=\"nofollow\" title=\"twitter\"><i class=\"fa fa-linkedin\" aria-hidden=\"true\"></i></a>                <a href=\"https://github.com/Santostang\" target=\"_blank\" rel=\"nofollow\" title=\"GitHub\"><i class=\"fa fa-github\" aria-hidden=\"true\"></i></a>    </div>\n",
      "    <div class=\"nav\">\n",
      "        <ul><li><a href=\"http://www.santostang.com/\">首页</a></li>\n",
      "<li><a href=\"http://www.santostang.com/sample-page/\">关于我</a></li>\n",
      "<li><a href=\"http://www.santostang.com/python%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab%e4%bb%a3%e7%a0%81/\">爬虫书代码</a></li>\n",
      "<li><a href=\"http://www.santostang.com/%e5%8a%a0%e6%88%91%e5%be%ae%e4%bf%a1/\">加我微信</a></li>\n",
      "<li><a href=\"https://santostang.github.io/\">EnglishSite</a></li>\n",
      "</ul>    </div>\n",
      "        <div class=\"weixin\">\n",
      "        <img src=\"http://www.santostang.com/wp-content/uploads/2018/07/qrcode_for_gh_370f70791e19_344-1.jpg\" alt=\"微信公众号\" width=\"50%\">\n",
      "        <p>微信公众号</p>\n",
      "    </div>\n",
      "    </header>\n",
      "\n",
      "<div id=\"main\">\n",
      "    <div class=\"row box\">\n",
      "        <div class=\"col-md-8\">\n",
      "                                <article class=\"article-list-1 clearfix\">\n",
      "                <header class=\"clearfix\">\n",
      "                    <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/15/4-3-%e9%80%9a%e8%bf%87selenium-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8a%93%e5%8f%96/\">4.3 通过selenium 模拟浏览器抓取</a></h1>\n",
      "                    <div class=\"post-meta\">\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 07月15日</span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/uncategorized/\" rel=\"category tag\">未分类</a></span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2018/07/15/4-3-%e9%80%9a%e8%bf%87selenium-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8a%93%e5%8f%96/#respond\">没有评论</a></span>\n",
      "                        <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "                    </div>\n",
      "                </header>\n",
      "                <div class=\"post-content clearfix\">\n",
      "                    <p>4.3 通过selenium 模拟浏览器抓取\n",
      "\n",
      "在上述的例子中，使用Chrome“检查”功能找到源地址还十分容易。但是有一些网站非常复杂，例如前面的天猫产品评论，使用“检查”功能很难找到调用的网页地址。除此之外，有一些数据...</p>\n",
      "                </div>\n",
      "            </article>\n",
      "                                                <article class=\"article-list-1 clearfix\">\n",
      "                <header class=\"clearfix\">\n",
      "                    <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/14/4-2-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80%e6%8a%93%e5%8f%96/\">4.2 解析真实地址抓取</a></h1>\n",
      "                    <div class=\"post-meta\">\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 07月14日</span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python-%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"category tag\">Python 网络爬虫</a></span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2018/07/14/4-2-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80%e6%8a%93%e5%8f%96/#respond\">没有评论</a></span>\n",
      "                        <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> <a href=\"http://www.santostang.com/tag/ajax/\" rel=\"tag\">ajax</a>,<a href=\"http://www.santostang.com/tag/python/\" rel=\"tag\">python</a>,<a href=\"http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"tag\">网络爬虫</a>,<a href=\"http://www.santostang.com/tag/%e7%bd%91%e9%a1%b5%e7%88%ac%e8%99%ab/\" rel=\"tag\">网页爬虫</a>,<a href=\"http://www.santostang.com/tag/%e8%a7%a3%e6%9e%90%e5%9c%b0%e5%9d%80/\" rel=\"tag\">解析地址</a></span>\n",
      "                    </div>\n",
      "                </header>\n",
      "                <div class=\"post-content clearfix\">\n",
      "                    <p>由于网易云跟帖停止服务，现在已经在此处中更新了新写的第四章。请参照文章：\n",
      "\n",
      "4.2 解析真实地址抓取\n",
      "\n",
      "虽然数据并没有出现在网页源代码中，我们也可以找到数据的真实地址，请求这个真实地址也可以获得想要的数据...</p>\n",
      "                </div>\n",
      "            </article>\n",
      "                                                <article class=\"article-list-1 clearfix\">\n",
      "                <header class=\"clearfix\">\n",
      "                    <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/14/%e7%ac%ac%e5%9b%9b%e7%ab%a0%ef%bc%9a%e5%8a%a8%e6%80%81%e7%bd%91%e9%a1%b5%e6%8a%93%e5%8f%96-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80-selenium/\">第四章- 动态网页抓取 (解析真实地址 + selenium)</a></h1>\n",
      "                    <div class=\"post-meta\">\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 07月14日</span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python-%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"category tag\">Python 网络爬虫</a></span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2018/07/14/%e7%ac%ac%e5%9b%9b%e7%ab%a0%ef%bc%9a%e5%8a%a8%e6%80%81%e7%bd%91%e9%a1%b5%e6%8a%93%e5%8f%96-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80-selenium/#respond\">没有评论</a></span>\n",
      "                        <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> <a href=\"http://www.santostang.com/tag/ajax/\" rel=\"tag\">ajax</a>,<a href=\"http://www.santostang.com/tag/javascript/\" rel=\"tag\">javascript</a>,<a href=\"http://www.santostang.com/tag/python/\" rel=\"tag\">python</a>,<a href=\"http://www.santostang.com/tag/sselenium/\" rel=\"tag\">sselenium</a>,<a href=\"http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"tag\">网络爬虫</a></span>\n",
      "                    </div>\n",
      "                </header>\n",
      "                <div class=\"post-content clearfix\">\n",
      "                    <p>由于网易云跟帖停止服务，现在已经在此处中更新了新写的第四章。请参照文章：\n",
      "\n",
      "前面爬取的网页均为静态网页，这样的网页在浏览器中展示的内容都在 HTML 源代码中。但是，由于主流网站都使用JavaScript 展现网页内...</p>\n",
      "                </div>\n",
      "            </article>\n",
      "                                                <article class=\"article-list-1 clearfix\">\n",
      "                <header class=\"clearfix\">\n",
      "                    <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/11/%e3%80%8a%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e5%ae%9e%e8%b7%b5%e3%80%8b%e4%b8%80%e4%b9%a6%e5%8b%98%e8%af%af/\">《网络爬虫：从入门到实践》一书勘误</a></h1>\n",
      "                    <div class=\"post-meta\">\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 07月11日</span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python-%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"category tag\">Python 网络爬虫</a></span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2018/07/11/%e3%80%8a%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e5%ae%9e%e8%b7%b5%e3%80%8b%e4%b8%80%e4%b9%a6%e5%8b%98%e8%af%af/#respond\">没有评论</a></span>\n",
      "                        <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "                    </div>\n",
      "                </header>\n",
      "                <div class=\"post-content clearfix\">\n",
      "                    <p>本书由于是第一版，因此还存在一些差错，希望各位读者谅解。\n",
      "\n",
      "另外，感谢各位读者的指正，现将本书的错误之处一并放在此处，方便其他读者更好阅读和使用此书。也欢迎大家在知乎私信或者留言给我，我会持续更新此...</p>\n",
      "                </div>\n",
      "            </article>\n",
      "                                                <article class=\"article-list-1 clearfix\">\n",
      "                <header class=\"clearfix\">\n",
      "                    <h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/04/hello-world/\">Hello world!</a></h1>\n",
      "                    <div class=\"post-meta\">\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-calendar\"></i> 07月04日</span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-folder-open-o\"></i> <a href=\"http://www.santostang.com/category/python-%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" rel=\"category tag\">Python 网络爬虫</a></span>\n",
      "                        <span class=\"meta-span\"><i class=\"fa fa-commenting-o\"></i> <a href=\"http://www.santostang.com/2018/07/04/hello-world/#comments\">1条评论</a></span>\n",
      "                        <span class=\"meta-span hidden-xs\"><i class=\"fa fa-tags\" aria-hidden=\"true\"></i> </span>\n",
      "                    </div>\n",
      "                </header>\n",
      "                <div class=\"post-content clearfix\">\n",
      "                    <p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!\n",
      "\n",
      "各位读者，由于网易云跟帖在本书出版后已经停止服务，书中的第四章已经无法使用。所以我将本书的评论系统换成了来必力...</p>\n",
      "                </div>\n",
      "            </article>\n",
      "                                    <nav style=\"float:right\">\n",
      "                            </nav>\n",
      "        </div>\n",
      "        <div class=\"col-md-4 hidden-xs hidden-sm\">\n",
      "            <aside class=\"widget clearfix\">\n",
      "    <form id=\"searchform\" action=\"http://www.santostang.com\">\n",
      "        <div class=\"input-group\">\n",
      "            <input type=\"search\" class=\"form-control\" placeholder=\"搜索…\" value=\"\" name=\"s\">\n",
      "            <span class=\"input-group-btn\"><button class=\"btn btn-default\" type=\"submit\"><i class=\"fa fa-search\" aria-hidden=\"true\"></i></button></span>\n",
      "        </div>\n",
      "    </form>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "    <h4 class=\"widget-title\">文章分类</h4>\n",
      "    <ul class=\"widget-cat\">\n",
      "        \t<li class=\"cat-item cat-item-1\"><a href=\"http://www.santostang.com/category/uncategorized/\" >未分类</a> (1)\n",
      "</li>\n",
      "\t<li class=\"cat-item cat-item-3\"><a href=\"http://www.santostang.com/category/python-%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" >Python 网络爬虫</a> (4)\n",
      "</li>\n",
      "    </ul>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "    <h4 class=\"widget-title\">热门文章</h4>\n",
      "    <ul class=\"widget-hot\">\n",
      "        \n",
      "<li><a href=\"http://www.santostang.com/2018/07/11/%e3%80%8a%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e5%ae%9e%e8%b7%b5%e3%80%8b%e4%b8%80%e4%b9%a6%e5%8b%98%e8%af%af/\" target=\"_blank\" >《网络爬虫：从入门到实践》一书勘误</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2018/07/14/%e7%ac%ac%e5%9b%9b%e7%ab%a0%ef%bc%9a%e5%8a%a8%e6%80%81%e7%bd%91%e9%a1%b5%e6%8a%93%e5%8f%96-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80-selenium/\" target=\"_blank\" >第四章- 动态网页抓取 (解析真实地址 + selenium)</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2018/07/14/4-2-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80%e6%8a%93%e5%8f%96/\" target=\"_blank\" >4.2 解析真实地址抓取</a></li>\n",
      "<li><a href=\"http://www.santostang.com/2018/07/15/4-3-%e9%80%9a%e8%bf%87selenium-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8a%93%e5%8f%96/\" target=\"_blank\" >4.3 通过selenium 模拟浏览器抓取</a></li>    </ul>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "    <h4 class=\"widget-title\">随机推荐</h4>\n",
      "    <ul class=\"widget-hot\">\n",
      "            <li><a href=\"http://www.santostang.com/2018/07/14/4-2-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80%e6%8a%93%e5%8f%96/\" title=\"4.2 解析真实地址抓取\">4.2 解析真实地址抓取</a></li>\n",
      "            <li><a href=\"http://www.santostang.com/2018/07/11/%e3%80%8a%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e5%ae%9e%e8%b7%b5%e3%80%8b%e4%b8%80%e4%b9%a6%e5%8b%98%e8%af%af/\" title=\"《网络爬虫：从入门到实践》一书勘误\">《网络爬虫：从入门到实践》一书勘误</a></li>\n",
      "            <li><a href=\"http://www.santostang.com/2018/07/15/4-3-%e9%80%9a%e8%bf%87selenium-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8a%93%e5%8f%96/\" title=\"4.3 通过selenium 模拟浏览器抓取\">4.3 通过selenium 模拟浏览器抓取</a></li>\n",
      "            <li><a href=\"http://www.santostang.com/2018/07/14/%e7%ac%ac%e5%9b%9b%e7%ab%a0%ef%bc%9a%e5%8a%a8%e6%80%81%e7%bd%91%e9%a1%b5%e6%8a%93%e5%8f%96-%e8%a7%a3%e6%9e%90%e7%9c%9f%e5%ae%9e%e5%9c%b0%e5%9d%80-selenium/\" title=\"第四章- 动态网页抓取 (解析真实地址 + selenium)\">第四章- 动态网页抓取 (解析真实地址 + selenium)</a></li>\n",
      "            <li><a href=\"http://www.santostang.com/2018/07/04/hello-world/\" title=\"Hello world!\">Hello world!</a></li>\n",
      "        </ul>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "    <h4 class=\"widget-title\">标签云</h4>\n",
      "    <div class=\"widget-tags\">\n",
      "        <a href=\"http://www.santostang.com/tag/ajax/\" class=\"tag-cloud-link tag-link-7 tag-link-position-1\" style=\"color:#e1b0f0;font-size: 22pt;\" aria-label=\"ajax (2个项目);\">ajax</a>\n",
      "<a href=\"http://www.santostang.com/tag/javascript/\" class=\"tag-cloud-link tag-link-8 tag-link-position-2\" style=\"color:#e507ec;font-size: 8pt;\" aria-label=\"javascript (1个项目);\">javascript</a>\n",
      "<a href=\"http://www.santostang.com/tag/python/\" class=\"tag-cloud-link tag-link-5 tag-link-position-3\" style=\"color:#8d85ed;font-size: 22pt;\" aria-label=\"python (2个项目);\">python</a>\n",
      "<a href=\"http://www.santostang.com/tag/sselenium/\" class=\"tag-cloud-link tag-link-4 tag-link-position-4\" style=\"color:#33e98a;font-size: 8pt;\" aria-label=\"sselenium (1个项目);\">sselenium</a>\n",
      "<a href=\"http://www.santostang.com/tag/%e7%bd%91%e7%bb%9c%e7%88%ac%e8%99%ab/\" class=\"tag-cloud-link tag-link-6 tag-link-position-5\" style=\"color:#12100e;font-size: 22pt;\" aria-label=\"网络爬虫 (2个项目);\">网络爬虫</a>\n",
      "<a href=\"http://www.santostang.com/tag/%e7%bd%91%e9%a1%b5%e7%88%ac%e8%99%ab/\" class=\"tag-cloud-link tag-link-9 tag-link-position-6\" style=\"color:#1c1dc0;font-size: 8pt;\" aria-label=\"网页爬虫 (1个项目);\">网页爬虫</a>\n",
      "<a href=\"http://www.santostang.com/tag/%e8%a7%a3%e6%9e%90%e5%9c%b0%e5%9d%80/\" class=\"tag-cloud-link tag-link-10 tag-link-position-7\" style=\"color:#de4541;font-size: 8pt;\" aria-label=\"解析地址 (1个项目);\">解析地址</a>    </div>\n",
      "</aside>\n",
      "<aside class=\"widget clearfix\">\n",
      "    <h4 class=\"widget-title\">友情链接</h4>\n",
      "    <ul class=\"widget-links\">\n",
      "            </ul>\n",
      "</aside>\n",
      "        </div>\n",
      "    </div>\n",
      "</div>\n",
      "\n",
      "<div class=\"footer_search visible-xs visible-sm\">\n",
      "    <form id=\"searchform\" action=\"http://www.santostang.com\">\n",
      "        <div class=\"input-group\">\n",
      "            <input type=\"search\" class=\"form-control\" placeholder=\"搜索…\" value=\"\" name=\"s\">\n",
      "            <span class=\"input-group-btn\"><button class=\"btn btn-default\" type=\"submit\"><i class=\"fa fa-search\" aria-hidden=\"true\"></i></button></span>\n",
      "        </div>\n",
      "    </form>\n",
      "</div>\n",
      "<footer id=\"footer\">\n",
      "    <div class=\"copyright\">\n",
      "        <p><i class=\"fa fa-copyright\" aria-hidden=\"true\"></i> 2018 <b>唐松 Santos</b></p>\n",
      "        <p>Powered by <b>WordPress</b>. Theme by <a href=\"https://tangjie.me/jiestyle-two\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"WordPress 主题模板\" target=\"_blank\"><b>JieStyle Two</b></a> | </p>\n",
      "    </div>\n",
      "    <div style=\"display:none;\">代码在页面底部，统计标识不会显示，但不影响统计效果</div>\n",
      "</footer>\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/js/skel.min.js\"></script>\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/js/util.min.js\"></script>\n",
      "<script type=\"text/javascript\" src=\"http://www.santostang.com/wp-content/themes/JieStyle-Two-master/js/nav.js\"></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>\n",
      "<script type='text/javascript' src='http://www.santostang.com/wp-content/plugins/captcha-bank/assets/global/plugins/custom/js/front-end-script.js?ver=4.9.9'></script>\n",
      "<script>\n",
      "$(function() {\n",
      "    $('[data-toggle=\"tooltip\"]').tooltip()\n",
      "});\n",
      "</script>\n",
      "<script>\n",
      "(function(){\n",
      "    var bp = document.createElement('script');\n",
      "    var curProtocol = window.location.protocol.split(':')[0];\n",
      "    if (curProtocol === 'https') {\n",
      "        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';\n",
      "    }\n",
      "    else {\n",
      "        bp.src = 'http://push.zhanzhang.baidu.com/push.js';\n",
      "    }\n",
      "    var s = document.getElementsByTagName(\"script\")[0];\n",
      "    s.parentNode.insertBefore(bp, s);\n",
      "})();\n",
      "</script>\n",
      "</body>\n",
      "</html>\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "r = requests.get('http://www.santostang.com/')\n",
    "print (\"文本编码:\", r.encoding)\n",
    "print (\"响应状态码:\", r.status_code)\n",
    "print (\"字符串方式的响应体:\", r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.3定制Requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.1\t传递URL参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:24:25.070550Z",
     "start_time": "2019-01-04T12:24:24.548843Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "URL已经正确编码: http://httpbin.org/get?key1=value1&key2=value2\n",
      "字符串方式的响应体: \n",
      " {\n",
      "  \"args\": {\n",
      "    \"key1\": \"value1\", \n",
      "    \"key2\": \"value2\"\n",
      "  }, \n",
      "  \"headers\": {\n",
      "    \"Accept\": \"*/*\", \n",
      "    \"Accept-Encoding\": \"gzip, deflate\", \n",
      "    \"Cache-Control\": \"max-age=259200\", \n",
      "    \"Connection\": \"close\", \n",
      "    \"Host\": \"httpbin.org\", \n",
      "    \"User-Agent\": \"python-requests/2.14.2\"\n",
      "  }, \n",
      "  \"origin\": \"203.205.141.49\", \n",
      "  \"url\": \"http://httpbin.org/get?key1=value1&key2=value2\"\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "key_dict = {'key1': 'value1', 'key2': 'value2'}\n",
    "r = requests.get('http://httpbin.org/get', params=key_dict)\n",
    "print (\"URL已经正确编码:\", r.url)\n",
    "print (\"字符串方式的响应体: \\n\", r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.2\t定制请求头"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:24:57.417442Z",
     "start_time": "2019-01-04T12:24:57.162030Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "响应状态码: 200\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "headers = {\n",
    "'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36',\n",
    "'Host': 'www.santostang.com'\n",
    "}\n",
    "r = requests.get('http://www.santostang.com/', headers=headers)\n",
    "print (\"响应状态码:\", r.status_code)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.3\t发送POST请求\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:25:25.783032Z",
     "start_time": "2019-01-04T12:25:25.313007Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"args\": {}, \n",
      "  \"data\": \"\", \n",
      "  \"files\": {}, \n",
      "  \"form\": {\n",
      "    \"key1\": \"value1\", \n",
      "    \"key2\": \"value2\"\n",
      "  }, \n",
      "  \"headers\": {\n",
      "    \"Accept\": \"*/*\", \n",
      "    \"Accept-Encoding\": \"gzip, deflate\", \n",
      "    \"Cache-Control\": \"max-age=259200\", \n",
      "    \"Connection\": \"close\", \n",
      "    \"Content-Length\": \"23\", \n",
      "    \"Content-Type\": \"application/x-www-form-urlencoded\", \n",
      "    \"Host\": \"httpbin.org\", \n",
      "    \"User-Agent\": \"python-requests/2.14.2\"\n",
      "  }, \n",
      "  \"json\": null, \n",
      "  \"origin\": \"203.205.141.49\", \n",
      "  \"url\": \"http://httpbin.org/post\"\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "key_dict = {'key1': 'value1', 'key2': 'value2'}\n",
    "r = requests.post('http://httpbin.org/post', data=key_dict)\n",
    "print (r.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3.4\t超时\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:26:14.105522Z",
     "start_time": "2019-01-04T12:26:13.979185Z"
    }
   },
   "outputs": [
    {
     "ename": "ConnectTimeout",
     "evalue": "HTTPConnectionPool(host='web-proxy.oa.com', port=8080): Max retries exceeded with url: http://www.santostang.com/ (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x0000020A727B2CC0>, 'Connection to web-proxy.oa.com timed out. (connect timeout=0.001)'))",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mtimeout\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36m_new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    140\u001b[0m             conn = connection.create_connection(\n\u001b[1;32m--> 141\u001b[1;33m                 (self.host, self.port), self.timeout, **extra_kw)\n\u001b[0m\u001b[0;32m    142\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\connection.py\u001b[0m in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m     82\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0merr\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 83\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     84\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\connection.py\u001b[0m in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m     72\u001b[0m                 \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msource_address\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 73\u001b[1;33m             \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     74\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0msock\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mtimeout\u001b[0m: timed out",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mConnectTimeoutError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    599\u001b[0m                                                   \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 600\u001b[1;33m                                                   chunked=chunked)\n\u001b[0m\u001b[0;32m    601\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    355\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 356\u001b[1;33m             \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mhttplib_request_kw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    357\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m   1238\u001b[0m         \u001b[1;34m\"\"\"Send a complete request to the server.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1239\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_send_request\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1240\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_send_request\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m   1284\u001b[0m             \u001b[0mbody\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_encode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'body'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1285\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendheaders\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1286\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mendheaders\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m   1233\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mCannotSendHeader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1234\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_send_output\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage_body\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1235\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_send_output\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m   1025\u001b[0m         \u001b[1;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_buffer\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1026\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1027\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, data)\u001b[0m\n\u001b[0;32m    963\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mauto_open\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 964\u001b[1;33m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    965\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36mconnect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    165\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 166\u001b[1;33m         \u001b[0mconn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_new_conn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    167\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_prepare_conn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mconn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connection.py\u001b[0m in \u001b[0;36m_new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    145\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Connection to %s timed out. (connect timeout=%s)\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 146\u001b[1;33m                 (self.host, self.timeout))\n\u001b[0m\u001b[0;32m    147\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mConnectTimeoutError\u001b[0m: (<requests.packages.urllib3.connection.HTTPConnection object at 0x0000020A727B2CC0>, 'Connection to web-proxy.oa.com timed out. (connect timeout=0.001)')",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mMaxRetryError\u001b[0m                             Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    437\u001b[0m                     \u001b[0mretries\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax_retries\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 438\u001b[1;33m                     \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    439\u001b[0m                 )\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    648\u001b[0m             retries = retries.increment(method, url, error=e, _pool=self,\n\u001b[1;32m--> 649\u001b[1;33m                                         _stacktrace=sys.exc_info()[2])\n\u001b[0m\u001b[0;32m    650\u001b[0m             \u001b[0mretries\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\packages\\urllib3\\util\\retry.py\u001b[0m in \u001b[0;36mincrement\u001b[1;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[0;32m    387\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mnew_retry\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_exhausted\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 388\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mMaxRetryError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_pool\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merror\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mResponseError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcause\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    389\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mMaxRetryError\u001b[0m: HTTPConnectionPool(host='web-proxy.oa.com', port=8080): Max retries exceeded with url: http://www.santostang.com/ (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x0000020A727B2CC0>, 'Connection to web-proxy.oa.com timed out. (connect timeout=0.001)'))",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mConnectTimeout\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-2866e1d77c09>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mlink\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"http://www.santostang.com/\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlink\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;36m0.001\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mproxies\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mproxies\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(url, params, **kwargs)\u001b[0m\n\u001b[0;32m     70\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     71\u001b[0m     \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'allow_redirects'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 72\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'get'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     73\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     74\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(method, url, **kwargs)\u001b[0m\n\u001b[0;32m     56\u001b[0m     \u001b[1;31m# cases, and look like a memory leak in others.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     57\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0msessions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 58\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     59\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     60\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m    516\u001b[0m         }\n\u001b[0;32m    517\u001b[0m         \u001b[0msend_kwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msettings\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 518\u001b[1;33m         \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0msend_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    519\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    520\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m    637\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    638\u001b[0m         \u001b[1;31m# Send the request\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 639\u001b[1;33m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0madapter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    640\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    641\u001b[0m         \u001b[1;31m# Total elapsed time of the request (approximately)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    492\u001b[0m                 \u001b[1;31m# TODO: Remove this in 3.0.0: see #2811\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    493\u001b[0m                 \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreason\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNewConnectionError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 494\u001b[1;33m                     \u001b[1;32mraise\u001b[0m \u001b[0mConnectTimeout\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    495\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    496\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreason\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mResponseError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mConnectTimeout\u001b[0m: HTTPConnectionPool(host='web-proxy.oa.com', port=8080): Max retries exceeded with url: http://www.santostang.com/ (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x0000020A727B2CC0>, 'Connection to web-proxy.oa.com timed out. (connect timeout=0.001)'))"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "link = \"http://www.santostang.com/\" \n",
    "r = requests.get(link, timeout= 0.001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {
    "height": "138px",
    "width": "252px"
   },
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
